#ifndef __ERROR_H
#define __ERROR_H

#include "../build.h"

namespace utils {

namespace ec {

constexpr uint8_t OK = 0x00;
constexpr uint8_t FLASH_ERR = 0x01;
constexpr uint8_t STORE_SUM_FAIL = 0x02;
constexpr uint8_t PARSE_ERR = 0x03;
constexpr uint8_t INVALID = 0x04;
constexpr uint8_t OTA_ID_INVALID = 0x05;
constexpr uint8_t OTA_MD5_INVALID = 0x06;
constexpr uint8_t OTA_PKG_INVALID = 0x07;

constexpr uint8_t MDB_RESP_TIMEOUT = 0x08;
constexpr uint8_t MDB_INVALID = 0x09;
constexpr uint8_t MDB_CHECK_SUM_FAIL = 0x0A;
constexpr uint8_t MDB_TIMEOUT = 0x0B;

} // namespace ec

struct Error {

    inline Error(uint8_t ec) : err_code(ec) {}
    inline Error() : err_code(ec::OK) {}

    inline bool is_ok() const { return err_code == ec::OK; }

    inline Error &operator=(uint8_t ec) {
        this->err_code = ec;
        return *this;
    }

    inline operator bool() const { return err_code != ec::OK; }

    uint8_t err_code;
};

} // namespace utils

#endif
